package com.itzhoun.publish;

import cn.hutool.json.JSONObject;
import com.itzhoun.entity.UserEntity;
import com.itzhoun.model.BaseEvent;
import com.itzhoun.model.HelloApplicationEvent;
import com.itzhoun.model.WatchApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 *
 * @author 周楠
 * @Date 2022/10/28/下午 7:40
 */
@Component
public class EventPublisher implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void publishHelloEvent(JSONObject userEntity){
        this.applicationEventPublisher.publishEvent(new HelloApplicationEvent(userEntity));

    }

    public void publishWatchEvent(String message){
        this.applicationEventPublisher.publishEvent(new WatchApplicationEvent(message));

    }
}
